const net = require('net');
const { join } = require('path');

let ws = require('fs').createWriteStream(join(__dirname, 'msg.txt'));

// socket 代表跟客户端的连接
const server = net.createServer(socket => {
    socket.pause(); // 暂停
    socket.setTimeout(3 * 1000);
    socket.on('timeout',() => {
        socket.pipe(ws, { end : false });
    })
    /* setTimeout(() => {
        // pipe默认情况下，当可读流读到末尾会关系可写流
        socket.pipe(ws, { end : false });
    }, 5000); */
});

server.listen('8080',() => {
    console.log('服务器连接成功');
})